package com.henu.art.test;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.henu.art.entity.Teacher;
import com.henu.art.mapper.TeacherMapper;
import com.henu.art.util.EncodeUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
public class OperateDataBase {
//初始化所有教师密码等于工号
    @Autowired
    private TeacherMapper teacherMapper;

    @Test
    public void updateTeacherPasswords() {
        QueryWrapper<Teacher> queryWrapper = new QueryWrapper<>();
        queryWrapper.isNotNull("id");
        List<Teacher> teachers = teacherMapper.selectList(queryWrapper);
        for (Teacher teacher : teachers) {
            String encryptedPassword = EncodeUtil.encodePassword(teacher.getId());
            teacher.setPassword(encryptedPassword);
            teacherMapper.updateById(teacher);
        }

    }
}